import { GetCheckCodeRes, LoginDto } from "@/types/auth";
import { Result } from "@/types/common";
import request from "@/utils/request";
import { AUTH_KEY } from "@/constant";

export const getCheckCode = (): Promise<Result<GetCheckCodeRes>> => {
  return request.get("/common/captcha");
};

export const login = (data: LoginDto): Promise<Result<{ token: string }>> => {
  return request.post("/auth/login", data);
};

export const getAuth = () => {
  return localStorage.getItem(AUTH_KEY);
};

export const setAuth = (auth: string) => {
  localStorage.setItem(AUTH_KEY, auth);
};

export const removeAuth = () => {
  localStorage.removeItem(AUTH_KEY);
};
